<!DOCTYPE>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>医院地区编辑</title>
    <link rel="stylesheet" href="../static/lib/layui/css/layui.css"  media="all">
    <link rel="stylesheet" type="text/css" href="../static/plugin/layer/skin/layer.css">
    <link rel="stylesheet" type="text/css" href="../static/css/dj-css.css">

    <style type="text/css">
        body{padding-top:10px;}
        .fl{float:left;}
        .fr{float:right;}
        .por{position: relative;}
        #pagination{margin:0 20px;}
        .layui-form{margin:0 20px;}
        .update input{position: absolute;height:36px;width:100px;z-index:3;opacity: .01;cursor: pointer;}
        .update span{color:#5FB878;position: absolute;left:0;top:0;width: 110px;height:36px;text-align:center;line-height:36px;border:1px solid #ddd;border-bottom-right-radius: 2px;border-top-right-radius:2px;font-size:20px;}
        .update i{color:#000;font-style: normal;font-size:16px;}
        /*复选框样式*/
        ul{border:1px solid #ddd;}
        ul li{height:32px;line-height:32px;}
        .checkbox{position: relative;width:100px;height:32px;padding-left:32px;}
        .checkbox input{position: absolute;left:0;top:0;width:100px;height:32px;opacity:.01;z-index:2;cursor:pointer;}
        .checkbox input:hover+i.checkboxIcon{border:1px solid #5FB878;}
        .checkbox i.checkedColor{color:#fff;border:1px solid #5FB878;background: #5FB878;}
        /*table td ,table th{border:1px solid #bbb;padding:0 5px;font-size:14px;}*/
        .checkbox i.checkboxIcon{position: absolute;width:22px;height:22px;line-height:22px;text-align:center; text-indent: -8px;border:1px solid #ddd;top:0;bottom:0;left:0;margin:auto;z-index:1;font-size:16px;color:#ddd;}
        /*三角旋转*/
        .downTriangle{transition:all 0.5s;}
        .downTriangle.downRotate{transform: rotate(90deg);}
        .x-red{color:red;}
        .layui-form-item{line-height: 38px;}
    </style>
</head>
<body>
<div id="createApp">
    <fieldset class="layui-elem-field layui-field-title" >
        <legend>用户</legend>
    </fieldset>
    <form action="">
        <div class="layui-form-item">
            <label class="layui-form-label">所属大区</label>
            <div class="layui-input-inline">
                <input type="text" name="userCode" v-model="parameter.region" lay-verify="required" placeholder="请输入所属大区" autocomplete="off" class="layui-input" @blur="verify(parameter.region)">
            </div>
            <span class="x-red">*必填</span>
        </div>

        <div class="layui-form-item">
            <div class="dj-select dj-select-inline">
                <label>所属省市</label>
                <div class="dj-select-content">
                    <div class="dj-select-input" flag = 'true'>
                        <span class="dj-selected" id="parentDeptId" type="text" name=""  selectedCode='' >请选择所属省份</span>
                        <i></i>
                    </div>
                    <ul class="dj-select-list" dj-this=''>
                        <li v-for="item in deptList" :code="item.id"  :class="{'selected':item.dval == parameter.province}" @click="selectSubDept(item.id)">{{item.dval}}</li>
                    </ul>
                </div>
            </div>

            <div class="dj-select dj-select-inline" style="margin-left:32px;">
                <div class="dj-select-content">
                    <div class="dj-select-input" flag = 'true'>
                        <span class="dj-selected" id="deptId" type="text" name=""  selectedCode='' >请选择所属城市</span>
                        <i></i>
                    </div>
                    <ul class="dj-select-list" dj-this=''>
                        <!--<li code=''>请选择所属部门</li>-->
                        <li v-for="subItem in subDeptList" :code="subItem.id" :class="{'selected':subItem.dval == parameter.city}">{{subItem.dval}}</li>
                    </ul>
                </div>
            </div>
            <span class="x-red">*必填</span>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">医院编号</label>
            <div class="layui-input-inline">
                <input type="text" name="userCode" v-model="parameter.dms_code" lay-verify="required" placeholder="请输入医院编号" autocomplete="off" class="layui-input" @blur="verify(parameter.dms_code)">
            </div>
            <span class="x-red">*必填</span>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">医院名称</label>
            <div class="layui-input-inline">
                <input type="text" name="userCode" v-model="parameter.hospital" lay-verify="required" placeholder="请输入医院名称" autocomplete="off" class="layui-input" @blur="verify(parameter.hospital)">
            </div>
            <span class="x-red">*必填</span>
        </div>

    </form>
    <div class="layui-form-item">
        <label class="layui-form-label"></label><button class="layui-btn" lay-submit="" lay-filter="demo2" @click="sub">提交</button>
    </div>
</div>
<script src="../static/lib/jquery.min.js"></script>
<script src="../static/lib/layui/layui.js" charset="utf-8"></script>
<script src="../static/lib/vue.min.js"></script>
<script src="../static/lib/x-layui.js"></script>
<script src="../static/lib/dj-js.js"></script>
<script type="text/javascript">
    var userId='$!{qsDictHospital.id}';
    var provinceId='$!{qsDictHospital.provinceId}';
    console.log(userId);
    var VM = new Vue({
        el:"#createApp",
        data:{
            deptList:[],
            subDeptList:[],
            myRoleIdList:[],
            roleList:[],
            parameter:{
                region:'$!{qsDictHospital.region}',
                province:'$!{qsDictHospital.province}',
                city:'$!{qsDictHospital.city}',
                hospital:'$!{qsDictHospital.hospital}',
                dms_code:'$!{qsDictHospital.dms_code}',
                id:''
            },
            downShowFlag:false,
            parentDeptIdFlag:'',
            pid:'',
            defaultSubDept:'',
            defaultDept:''
        },
        created:function(){
            this.getDeptList();
            this.selectSubDept(provinceId);
            $('#parentDeptId').html(this.parameter.province);
            $('#parentDeptId').attr("selectedCode",provinceId);
            $('#deptId').html(this.parameter.city);
        },
        methods:{
            verify:function (item) {
                if(item == ""){
                    layer.msg("必填项不能为空！", {icon: 5});
                    return false;
                }
            },
            sub:function () {
                var _this = this;

                if(this.parameter.region == "" ){
                    layer.msg("请输入所属大区！", {icon: 5});
                    return false;
                }else if(_this.parameter.city == "" || _this.parameter.city == null || _this.parameter.city == " "){
                    layer.msg("请选择所属省市！", {icon: 5});
                    return false;
                }else if(this.parameter.dms_code == ""){
                    layer.msg("请输入医院编号！", {icon: 5});
                    return false;
                }else if(this.parameter.hospital == ""){
                    layer.msg("请输入医院名称！", {icon: 5});
                    return false;
                }
                _this.parameter.province = $("#parentDeptId").html();
                _this.parameter.city = $("#parentDeptId").html();
                _this.parameter.id = userId;

                $.ajax({
                    type: "post",
                    url: "../StatisticsWeb/saveOrUpdateQsDictHospital.do",
                    data:_this.parameter,
                    dataType: "json",
                    success: function(data){
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                        parent.window.location.reload();
                        window.location.href = "javascript:location.replace(location.href)";
                    }
                });
            },
            getRoleList:function(){
                var _this = this;
                $.ajax({
                    type:"post",
                    url:'../role/allList.do',
                    dataType:"json",
                    success:function(res){
                        _this.roleList = res.result.roles;
                        console.log(_this.roleList);
                        if(_this.myRoleList){
                            _this.roleList.forEach(function(item,index){
                                _this.myRoleList.forEach(function(item1,index1){
                                    if(item.pkRoleId == item1.pkRoleId){
//                                        console.log(item.pkRoleId);
                                        if(typeof item.checked == "undefined"){
                                            Vue.set(item,"checked",true);
                                        }else{
                                            item.checked = !item.checked;
                                        }
                                    }
                                });
                            });
                        }
                    }
                })
            },
            selectRole:function (item) {
                if(typeof item.checked == "undefined"){
                    Vue.set(item,"checked",true);
                }else{
                    item.checked = !item.checked;
                }
            },
            downShow:function(){
                this.downShowFlag = !this.downShowFlag;
            },
            getDeptList:function(){
                var _this=this;

                $.ajax({
                    type: "post",
                    url: "../StatisticsWeb/provinceList.do",
                    dataType: "json",
                    success: function(data){
                        console.log(data);
                        _this.deptList=data.result.provinceList;
                    }
                });

            },
            selectSubDept:function(id){

                var _this = this;

                if(!id){
                    return;
                }
                $("#deptId").html("").attr("selectedCode",'');
                $.ajax({
                    type: "post",
                    url: "../StatisticsWeb/cityList.do?id="+
                    id,
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
                        _this.subDeptList = data.result.cityList;
                        $('#deptId').html(_this.subDeptList[0].dval);
                    }
                });



            }
        }
    });//vue 实例结束
    layui.use(['layer',"form",'laydate'], function(){
        var form = layui.form(),
                layer = layui.layer,
                laydate = layui.laydate;
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input.checkbox');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
    });

</script>
</body>
</html>